package com.springboot.prac.prac04_thread;

import java.util.concurrent.*;

public class MyThreadExecutor {

    public static void main(String[] args) {
        MyThreadExecutor executor = new MyThreadExecutor();
        executor.run();
    }

    public void run() {
        ExecutorService executor = threadPoolExecutor();
        executor.execute(new Thread01());

        System.out.println("线程池马上关闭");
        executor.shutdownNow();

        executor.execute(new Thread02());
    }

    class Thread01 implements Runnable {
        @Override
        public void run() {
            for (int i = 0; i < 50; i++) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
            }
        }
    }

    class Thread02 implements Runnable {
        @Override
        public void run() {
            System.out.println("线程2执行、、、");
        }
    }


    public static ExecutorService threadPoolExecutor() {
//        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
//                10,
//                1,
//                TimeUnit.SECONDS,
//                new LinkedBlockingDeque<>());
        ExecutorService executor = Executors.newFixedThreadPool(2);
        return executor;
    }
}
